export default {
  methods: {
    $errorTip(err) {
      if (!err || !err.code) {
        this.$message({
          message: this.$t('common.serviceerror'),
          type: 'error',
        })
      } else {
        if (err && err.code && err.code.toString().indexOf('1005') !== -1) {
          this.$confirm(this.$t('common.logoutTip'), this.$t('common.logout'), {
            confirmButtonText: this.$t('common.reLogin'),
            cancelButtonText: this.$t('common.cancel'),
            type: 'warning',
          })
            .then(() => {
              top.location.href = this.$UNITECHSJS.indexurl
            })
            .catch(() => {})
        } else {
          this.$message({
            message: err.tip || err.msg,
            type: 'error',
          })
        }
      }
    },
    $openTab(clickMenu) {
      const baseUrl = process.env.VUE_APP_BASE_STATIC_URL
        ? process.env.VUE_APP_BASE_STATIC_URL === '/'
          ? ''
          : process.env.VUE_APP_BASE_STATIC_URL
        : ''
      if (window.top.$vm && window.top.$vm.$store) {
        clickMenu.path = `${baseUrl}${clickMenu.path}`
        window.top.$vm.$store
          .dispatch('addVisitedViews', clickMenu)
          .then(() => {
            window.top.$vm.$store.dispatch('changeSelPage', clickMenu.path)
          })
      } else {
        let openUrl = clickMenu.path
        if (openUrl) {
          openUrl = `${baseUrl}/views/${openUrl}`
          window.open(openUrl)
        }
      }
    },
    $closeTab() {
      if (
        window.top.$vm &&
        window.top.$vm.$ &&
        window.top.$vm.$('.activeTag.tagClazz i.el-icon-close')
      )
        window.top.$vm.$('.activeTag.tagClazz i.el-icon-close').click()
      else window.close()
    },
  },
}
